<script>
	var QQMapWX = require('@/common/qqmap-wx-jssdk.min.js');
	var qqmapsdk;
	import {WS} from '@/common/WS.js'
	export default {
		onLaunch: function() {
			// // #ifdef APP-IOS
			//        plus.runtime.quit()
			// // #endif 
			
			var _this = this
			// this.$store.dispatch('getopenid')
			this.$store.dispatch('getuserinfo')
			this.$store.dispatch('getcate')
			
			this.ws = new WS(1)
			this.ws.open(()=>{
				_this.ws.send(JSON.stringify({
					userid: _this.$store.state.userid
				}))
				_this.$pushMsg(_this.$store.state.userid);
			})
				
			// 长连接 渲染数据
			this.ws.get(function (rets) {
				if (rets.indexOf('action') != -1) {
					rets = JSON.parse(rets);
					console.log(JSON.stringify(rets))
					if (rets) {
						// 渲染消息数量 Home/Privatechat/getreadcount
						if (rets.action == 'Home/Privatechat/getreadcount') {
							console.log(JSON.stringify(rets))
							var result = rets.data;
							var msgNum = {
								cnum: result.chat_count,
								mnum: result.message_count
							}
							_this.$store.commit('msgNum', msgNum);
						}
					}
				}
			})
		},
		onShow: function() {
			console.log('App Show ==========')
			// 获取系统信息
			uni.getSystemInfo({
				success(res) {
					uni.setStorage({key: 'brand', data:res.brand})
				}
			});
			
			
			var _this = this
			console.log(_this.$store.dispatch('pay_authentication'));
			
			uni.onNetworkStatusChange(function(res) {
				console.log('测测网络');
				console.log(res);
				if (res.isConnected) {
					uni.showModal({
						title: '系统提示',
						content: '当前设备网络已恢复',
						showCancel: false,
						confirmText: '知道了',
						success() {
							console.log(11111);
							uni.redirectTo({
								url:'/pages/index/index'
							})
						}
					})
				} else {
					uni.showModal({
						title: '系统提示',
						content: '当前设备无网络或网络较差',
						cancelText: '取消',
						confirmText: '确定',
						success: (res) => {
							if (res.confirm) {
								if(plus.os.name == 'iOS'){
									plus.runtime.launchApplication({action:'app-settings://'},function(e){
										console.log(e.message);
									})
								}else{
									uni.reLaunch({
										url:'/pages/index/index'
									})
								}
							} else {
								// #ifdef H5
								uni.navigateTo({
									url:'/pages/index/login'
								})
								// #endif
								// #ifdef APP-PLUS
								plus.runtime.quit()
								// #endif
							}
						}
					})
				}
			})
			
			console.log(_this.$store.state.hasLogin);
			if(_this.$store.state.hasLogin){
				qqmapsdk = new QQMapWX({
					key: '6NHBZ-CIZWP-LBHDR-V7NEE-WFODK-EXBPK'
				});
					// this.getuserinfo()
				_this.$store.dispatch('getUserPosition').then(res=>{
					console.log('地图');
					console.log(res)
					 qqmapsdk.reverseGeocoder({
						location: res.latitude + ',' +res.longitude,
						success(result) {
							uni.setStorageSync('dyCity', result.result.ad_info.city)
							console.log("城市")
							console.log(result.result.ad_info.city)
						}, 
						fail(err) {
						   uni.showToast('获取城市失败')
						},
						complete() {
						}
					 })
				})
			}
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
	page{
		background-color: #2A2931!important;
	}
	.flex{
		display: flex;
	}
	.disAl{
		align-items: center;
	}
	.flex-c{
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.flex-a{
		display: flex;
		align-items: center;
		justify-content: space-around;
	}
	.flex-w{
		display: flex;
		flex-wrap: wrap;
	}
	.flex-bt{
		display: flex;
		justify-content: space-between;
	}
	.flex-start{
		display: flex;
		justify-content: flex-start;
	}
	.flex-end{
		display: flex;
		justify-content: flex-end;
	}
	.flex-col{
		display: flex;
		flex-direction: column;
	}
	.new-btn {
		width: calc(100% - 60rpx);
		line-height: 100rpx;
		border-radius: 50rpx;
		background: linear-gradient(to right, #d9a14e, #b57e2c);
		color: #000;
		margin: 40rpx 30rpx;
	}
	.imagewh40{
		width: 80rpx;
		height: 80rpx;
	}
	.imagewh70{
		width: 140rpx;
		height: 140rpx;
	}
	.fontsize12{
		font-size: 24rpx;
	}
	.wid90{
		width: 90%;
	}
	.mar{
		margin: auto;
	}
</style>
